import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getter'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    userName: 'hdsdhgu',
    useInfo: {
      relation: "02",
      Name: "haha",
    },
    arr: [{
      sum: 1,
      relation: "02",
      relationName: "子女",
      isEnn: "X",
      familyMemberName: "李四",
      familyMemberLastName: "李",
      familyMemberFirstName: "四",
      gender: "1",
      count2: 1

    },
    {
      sum: 1,
      relation: "02",
      relationName: "子女",
      isEnn: "X",
      familyMemberName: "张三",
      familyMemberLastName: "李",
      familyMemberFirstName: "四",
      gender: "2",
      count: 1,
      count2: 1

    },
    {
      sum: 1,
      relation: "02",
      relationName: "子女",
      isEnn: "X",
      familyMemberName: "王武",
      familyMemberLastName: "李",
      familyMemberFirstName: "四",
      gender: "2",
      count: 1,
      count2: 1

    },
    {
      sum: 1,
      relation: "02",
      relationName: "子女",
      isEnn: "X",
      familyMemberName: "张三",
      familyMemberLastName: "李",
      familyMemberFirstName: "四",
      gender: "2",
      count: 1,
      count2: 1

    },
    ]
  },
  mutations: {//提交，对state中的数据进行操作,必须是函数
    //增加
    increment(state, v) {
      state.arr[v].count++
    },
    //负载提交
    sum(state, payLoad) {
      state.arr[payLoad.index].sum++
    }
  },
  actions: { //异步调用
    increment1({ commit }, payload) {
      commit('increment', payload.index)
    },
  },
  modules: {
  },
  getters   //定义公共方法，供多个组件使用
})
